﻿using System;
using System.Windows.Forms;

namespace StudentInfoSystem.View
{
    public partial class InfoForm : Form
    {
        public InfoForm()
        {
            InitializeComponent();
        }

        public InfoForm(string text)
        {
            InitializeComponent();
            rtB.Text = text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (fontDialog.ShowDialog() == DialogResult.OK)
            {
                if (rtB.SelectedText == "")
                {
                    rtB.Font = fontDialog.Font;
                }
                else
                {
                    rtB.SelectionFont = fontDialog.Font;
                }
            }
        }

        private void InfoForm_Load(object sender, EventArgs e)
        {
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                if (rtB.SelectedText == "")
                {
                    rtB.ForeColor = colorDialog.Color;
                }
                else
                {
                    rtB.SelectionColor = colorDialog.Color;
                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            saveFileDialog.DefaultExt = "*.rtf";
            saveFileDialog.Filter = "RTF Files|*.rtf";
            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK
                && (saveFileDialog.FileName.Length > 0))
            {
                try
                {
                    // Save the contents of the RichTextBox into the file. 
                    rtB.SaveFile(saveFileDialog.FileName);
                }
                catch (Exception)
                {
                    MessageBox.Show("Error! The File could not be saved!",
                                    "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        { 
            if (rtB.SelectedText != "")
            {
                rtB.SelectionAlignment = HorizontalAlignment.Center;
            }
        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            if (rtB.SelectedText != "")
            {
                rtB.SelectionAlignment = HorizontalAlignment.Right;
            }
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            if (rtB.SelectedText != "")
            {
                rtB.SelectionAlignment = HorizontalAlignment.Left;
            }
        }
    }
}